/*
 * @Author: szx
 * @Date: 2021-12-31 13:27:18
 * @LastEditTime: 2021-12-31 13:37:34
 * @Description:
 * @FilePath: \leetcode\300-399\376\376.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var wiggleMaxLength = function (nums) {
    if (nums.length == 1) return 1;
    let curDiff = 0; // 当前一对差值
    let preDiff = 0; // 前一对差值
    let result = 1; // 记录峰值个数，序列默认序列最右边有一个峰值
    for (let i = 0; i < nums.length - 1; i++) {
        curDiff = nums[i + 1] - nums[i];
        // 出现峰值
        if ((curDiff > 0 && preDiff <= 0) || (preDiff >= 0 && curDiff < 0)) {
            result++;
            preDiff = curDiff;
        }
    }
    return result;
};
console.log(wiggleMaxLength([2,2,3,4,4,3]))